package com.mkr.pojo;

/**
 * @author mkr
 * @version V1.0
 * @Project BookApp
 * @Package com.mkr.entity
 * @Description:
 * @Date 2022/5/16 10:10
 */
public class Page {
    //页码，当前页数
    private Integer pageIndex;
    //页大小 显示多少行数据
    private Integer pasgSize;
    //数据的总行数
    private Integer totalCounts;
    //总页数，共有多少页
    private Integer totalPages;
    //起始行，从第几行开始查询
    private Integer startRows;

    public Page() {

    }

    public Page(Integer pageIndex) {
        this.pageIndex = pageIndex;
        //初始化每页显示的条数，默认每页显示5条数据
        this.pasgSize = 5;
    }
    public Page(Integer pageIndex , Integer pasgSize ){
        this.pageIndex = pageIndex;
        this.pasgSize = pasgSize;
        //初始化每页显示的条数，默认每页显示5条数据
        this.pasgSize = 5;
        //计算从第几条开始查询
        this.setStartRowst((pageIndex - 1)*pasgSize);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPasgSize() {
        return pasgSize;
    }

    public void setPasgSize(Integer pasgSize) {
        this.pasgSize = pasgSize;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
        //设置总条数、计算总页数
        this.setTotalPages(totalCounts % pasgSize == 0?totalCounts/pasgSize:totalCounts/pasgSize+1);
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRowst(Integer startRows) {
        this.startRows = startRows;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageIndex=" + pageIndex +
                ", pasgSize=" + pasgSize +
                ", totalCounts=" + totalCounts +
                ", totalPages=" + totalPages +
                ", startCount=" + startRows +
                '}';
    }
}
